using System;
using System.Collections.Generic;
using System.Text;
using Northwoods.Go;

namespace Workflows.Diagrams
{
    [Serializable]
    public class RestrictedLinkingNewTool : GoToolLinkingNew
    {
        public RestrictedLinkingNewTool(GoView view)
            : base(view)
        {
        }

        public static bool ValidSubGraphLink(IGoPort fromPort, IGoPort toPort)
        {
            if (fromPort == null || fromPort.GoObject == null || toPort == null || toPort.GoObject == null)
                return false;
            MultiPortSubGraphPort fp = null;
            if (fromPort.GoObject.GetType() != typeof(GoPort))
                fp = (MultiPortSubGraphPort)fromPort.GoObject;
            if (fp != null)
            {
                if (fp.IsInput)
                {
                    if (!toPort.GoObject.IsChildOf(fp.Parent))
                    {
                        return false;
                    }
                }
                else
                {
                    if (toPort.GoObject.IsChildOf(fp.Parent))
                    {
                        return false;
                    }
                }
            }
          
            MultiPortSubGraphPort tp = null;
            if (toPort.GoObject.GetType() != typeof(GoPort))
                tp = (MultiPortSubGraphPort)toPort.GoObject;
            if (tp != null)
            {
                if (tp.IsInput)
                {
                    if (fromPort.GoObject.IsChildOf(tp.Parent))
                        return false;
                }
                else
                {
                    if (fromPort.GoObject.IsChildOf(tp.Parent))
                        return false;
                }
            }
            return true;
        }

        public override bool IsValidLink(IGoPort fromPort, IGoPort toPort)
        {
            return base.IsValidLink(fromPort, toPort);
        }
    }
}
